//
//  WJWelcomeController.m
//  weibo
//
//  Created by 王俊 on 16/1/4.
//  Copyright © 2016年 王俊. All rights reserved.
//

#import "WJWelcomeController.h"
#import "WJTabBarController.h"
#import "WJAccount.h"
#import "UIImageView+WebCache.h"


@interface WJWelcomeController()
@property(nonatomic,strong) UIImageView  *backgroundImage;
@property(nonatomic,strong) UIImageView  *avartImage;
@property(nonatomic,strong) UILabel  *welcomeLabel;
@end

@implementation WJWelcomeController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setUpView];
    
}

- (void)setUpView
{
    WJAccount *account = [WJAccount accountFromSandBox];
    
    _backgroundImage = [[UIImageView alloc]initWithFrame:self.view.bounds];
    _backgroundImage.image = [UIImage imageNamed:@"ad_background"];
    [self.view addSubview:_backgroundImage];
    
    _avartImage = [[UIImageView alloc]init];
    _avartImage.width = 80;
    _avartImage.height = 80;
    _avartImage.center = self.view.center;
    if (account.profile_image_url) {
        [_avartImage sd_setImageWithURL:[NSURL URLWithString:account.profile_image_url]];
        //_avartImage.image = [UIImage imageNamed:account.profile_image_url];
    }else{
        _avartImage.image = [UIImage imageNamed:@"avatar_default"];
    }
    _avartImage.layer.cornerRadius = _avartImage.width/2;
    _avartImage.clipsToBounds = true;
    [_backgroundImage addSubview:_avartImage];
    
    _welcomeLabel = [[UILabel alloc]init];
    _welcomeLabel.text = @"欢迎回来";
    _welcomeLabel.font = [UIFont boldSystemFontOfSize:17];
    _welcomeLabel.textColor = [UIColor darkGrayColor];
    [_welcomeLabel sizeToFit];
    _welcomeLabel.centerX = self.view.centerX;
    _welcomeLabel.y = SCNHEIGHT*5/12;
    _welcomeLabel.alpha = 0;
    [_backgroundImage addSubview:_welcomeLabel];
    
    
}


- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidLoad];
    [UIView animateWithDuration:1 animations:^{
        _avartImage.y -= SCNHEIGHT/4;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:2 animations:^{
            _welcomeLabel.alpha = 1;
        } completion:^(BOOL finished) {
            WJTabBarController *vc = [[WJTabBarController alloc]init];
            [UIApplication sharedApplication].keyWindow.rootViewController = vc;
        }];
    }];
}
@end
